# 其他转十进制
def func(num: str, r: int):
    n = len(num)
    s = 0
    for i in range(n):
        s = s * r + int(num[i])
    return s


# 十进制转其他进制
def func2(num: int, r: int):
    res = []
    while num != 0:
        res.insert(0, str(num % r))
        num //= r
    return "".join(res)


if __name__ == '__main__':
    b = '1010101001'
    o = '7676767377'
    h = '6345673'
    print(int(b, 2), int(o, 8), int(h, 16))
    print(func(b, 2), func(o, 8), func(h, 16))
    print(func2(681, 2), func2(1056698111, 8), func2(104093299, 16))
